//
//  YCInfoSetupViewController.m
//  YCSchool
//
//  Created by gmall on 16/5/24.
//  Copyright © 2016年 yanglinxia. All rights reserved.
//  资料设置

#import "YCInfoSetupViewController.h"
#import "YCUpdateNameViewController.h"

@interface YCInfoSetupViewController ()<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic, strong) UITableView *tableView;
@end

@implementation YCInfoSetupViewController

- (UITableView *)tableView
{
    if (!_tableView) {
        _tableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStyleGrouped];
        _tableView.backgroundColor = kBackgroudColor;
        _tableView.delegate = self;
        _tableView.dataSource = self;
    }
    return _tableView;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    [self yc_addBackBarButtonItem];
    self.navigationItem.title = @"资料设置";
    [self.view addSubview:self.tableView];
    [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.right.bottom.equalTo(self.view);
    }];
    //footerview
    UIView *footerView = [[UIView alloc] initWithSize:CGSizeMake(kScreenWidth, 100)];
    [footerView setPosition:CGPointZero atAnchorPoint:CGPointZero];
    self.tableView.tableFooterView = footerView;
    
    //delete
    UIButton *deleteFriendBtn = [[UIButton alloc] initWithSize:CGSizeMake(kScreenWidth - 2 * 40, 40)];
    [deleteFriendBtn setPosition:CGPointMake(kScreenWidth * 0.5, footerView.yc_height * 0.5) atAnchorPoint:CGPointMake(0.5, 0.5)];
    [footerView addSubview:deleteFriendBtn];
    deleteFriendBtn.backgroundColor = [UIColor redColor];
    deleteFriendBtn.layer.cornerRadius = 20;
    deleteFriendBtn.layer.masksToBounds = YES;
    [deleteFriendBtn setTitle:@"删除好友" forState:UIControlStateNormal];
}



#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 3;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    if (section == 0 || section == 1) {
        return 1;
    }else{
        return 2;
    }
}

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    if (section == 0) {
        return 10;
    }
    return 5;
}

-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 5;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:nil];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.textLabel.font = [UIFont systemFontOfSize:15];
    switch (indexPath.section) {
        case 0:
        {
            cell.textLabel.text = @"设置备注名";
            cell.detailTextLabel.font = [UIFont systemFontOfSize:14];
            cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
            cell.detailTextLabel.text = @"zhangsan";
        }
            break;
        case 1:
        {
            cell.textLabel.text = @"把Ta推荐给朋友";
            cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
        }
            break;
        case 2:
        {
            if (indexPath.row == 0) {
                cell.textLabel.text = @"加入黑名单";
                cell.accessoryType = UITableViewCellAccessoryNone;
                
                UISwitch *isAddSwitch = [[UISwitch alloc] initWithSize:CGSizeMake(50, 30)];
                [isAddSwitch setPosition:CGPointMake(kScreenWidth - 15, cell.yc_height * 0.5) atAnchorPoint:CGPointMake(1, 0.5)];
                [cell addSubview:isAddSwitch];
                isAddSwitch.on = NO;
                [isAddSwitch addTarget:self action:@selector(valueChange:) forControlEvents:UIControlEventValueChanged];
                
            }else{
                cell.textLabel.text = @"举报";
                cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
            }
        }
            break;
        default:
            break;
    }
    
    return cell;
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
    switch (indexPath.section) {
        case 0://设置备注名
        {
            YCUpdateNameViewController *updateNameVc = [[YCUpdateNameViewController alloc] initWithName:cell.detailTextLabel.text];
            [self.navigationController pushViewController:updateNameVc animated:YES];
        }
            break;
            
            
            
        default:
            break;
    }
    
}

#pragma mark -- 是否加入黑名单
-(void)valueChange:(UISwitch *)sender
{
    
}

@end
